<template>
    <div class="space whitepage page detailspage">
        <div class="parkSpace">
            <van-circle
                    v-model="currentRate"
                    :rate="rate"
                    :color="gradientColor"
                    size="280px"
                    :stroke-width="strokeWidth"
            />
        </div>
    </div>
</template>

<script>
    import {NavBar, Toast, Dialog, Icon} from 'vant';
    import "./css/parking.css";

    export default {
        name: "space",
        data() {
            return {
                currentRate: 0,
                gradientColor: {//渐变色
                    '0%': '#a363ac',
                    '100%': '#7460a5'
                },
                rate: 70,//百分比
                strokeWidth: 60,//宽度
                // carSpace:""
            };
        },
        mounted() {
            this.$api.parking.getSpace()
                .then(res => {
                    if (res.code == 0) {
                        this.carSpace = "剩余车位:" + res.data.restSpace;
                        this.rate = (res.data.totalSpace - res.data.restSpace) / res.data.totalSpace * 100;
                        var circle = document.querySelector(".van-circle")
                        var div = document.createElement("div");
                        div.innerHTML = '<div class="van-circle__text"><img src="http://guijiwenhua-new.oss-cn-shenzhen.aliyuncs.com/20191023/e44c388946794bbeb14f231f5b066bb9.png" class="circle_img"><div>' + this.carSpace + '</div></div>';
                        circle.insertBefore(div, circle.childNodes[1]);
                    } else {
                        this.carSpace = "查询异常";
                    }
                })
        }
    }
</script>

<style lang="less">

    .space {
        height: 100%;

        .parkSpace {
            margin-top: 25%;
            text-align: center;

            .circle_img {
                width: 45%;
                padding-bottom: 12%;
            }

            .van-circle__text {
                font-size: 25px;
            }
        }
    }

</style>